﻿@{
    Layout = "~/Views/Shared/_PopupLayout.cshtml";
}

@{Html.LacViet().tdLable("100");}

<style>
 fieldset {
    margin: 8px;
    border: 1px solid silver;
    padding: 8px;    
    border-radius: 4px;
}
legend{
    padding: 2px;        
}
</style>

<div>
    <form id="frm">
        <table style="width:100%;height: 80px">
            <tr>
                <td style="width:65%; vertical-align:top " >
                    <fieldset>
                    <legend>@Html.LacViet().Label("lblPrinOption", "Print Option")</legend>
                        <table style="width:100%">                    
                            <tr>
                                <td class="tdLabel"; height= "25px">                            
                                    @Html.LacViet().Label("lblFromDate", "From Date")
                                </td>
                                <td style="width:28%" >                            
                                    <div id="divFromDate" style="width:100%">
                                        @Html.LacViet().Date("FromDate", null,null,null)
                                    </div>
                                </td>
                                <td style="width:5%" >                            
                                    <div id="divFromDate" style="width:25px">
                                    </div>
                                </td>
                                <td class="tdLabel"; height= "25px">                            
                                    @Html.LacViet().Label("lblToDate", "To Date")
                                </td>
                                <td>                 
                                    <div id="divToDate" style="width:100%">
                                        @Html.LacViet().Date("ToDate", null , null,null)
                                    </div>                                       
                                </td>
                            </tr>                    

                            <tr>
                                <td class="tdLabel" height= "25px" >                            
                                    @Html.LacViet().Label("lblAuditCode", "Type")
                                </td>
                                <td>                            
                                    @Html.LacViet().ComboBox("AuditCode", "L0020" , 0,new {style = "width:100%"})
                                </td>
                            </tr>                                        

                         </table>    
                    </fieldset>
                </td>
                <td  style="vertical-align:top" >
                    <fieldset>
                        <legend>@Html.LacViet().Label("lblFilter", "Filter Option")</legend>
                        <table style="width:100%">                                        
                            <tr>
                              <td class="tdLabel" height= "25px" style="width:50%">                            
                                      @Html.LacViet().Label("lblBatchNo", "Batch No")
                                </td>
                                <td>                            
                                    @Html.LacViet().ComboBox("BatchNo", "tblBatchList" ,0,new {style = "width:100%"} )
                                </td>
                            </tr>                                        

                            <tr>
                                <td class="tdLabel" height= "25px">                            
                                    @Html.LacViet().Label("lblStatus", "Status")
                                </td>
                                <td>                            
                                    @Html.LacViet().ComboBox("Status", "L0027" , 0,new {style = "width:100%"})
                                </td>
                            </tr>                                        
                        </table>           
                    </fieldset>
                </td>
            </tr>
            <tr>
                <td colspan = "2">
                    <table cellpadding="3" cellspacing="3" style="table-layout:fixed;" width="100%">
                        <tr>
                            <td style="width: 100%;height:100%" valign="top">
                                 @{
                                    Guid SessionID = Guid.NewGuid();
                                }
                            
                                @Html.LacViet().GridView("grvtblVoucherList","tblVoucherList","SYS_tblVoucherList",true,false,null,"SessionID",SessionID.ToString(),true,false,"",false)
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</div>

<div class="Line">
</div>

<div>
    <div style="float: left" >
        <div class="buttons">
            <button class="positive" onclick= "Select()">
                <img style="width: 16px; height: 16px" src="@Html.BaseUrl()Content/images/toolbar/check.png" alt="" /> 
                @Html.LacViet().C("Select")
            </button> 
            <button class="positive" onclick= "UnSelect()">
                <img style="width: 16px; height: 16px" src="@Html.BaseUrl()Content/images/toolbar/uncheck.png" alt="" /> 
                @Html.LacViet().C("Unselect")
            </button> 
        </div>
    </div>

    <div  style="text-align:right">
        <div class="buttons">
            <button id="btnFilter" class="positive" onclick= "Filter()"> 
                <img src="@Html.BaseUrl()Content/images/toolbar/view.png" alt="" /> 
                @Html.LacViet().C("View")
	        </button>                                         

            <button id="btnSave" class="positive" onclick= "Print()">
                <img src="@Html.BaseUrl()Content/images/toolbar/Print.png" alt="" /> 
                @Html.LacViet().Label("lblPrint", "Print")
            </button> 

            <button class="positive" onclick= "Cancel()">
                <img src="@Html.BaseUrl()Content/images/toolbar/close.png" alt="" /> 
                @Html.LacViet().Label("lblCancel", "Cancel")
            </button> 
        </div>
    </div>
</div>

<script type="text/javascript">    
    var codeBasePopup = new CodeBasePopup();
    
    $(window).unload(function () {
        //alert('Handler for .unload() called.');
        PostServer('@Url.Action("ClearSession","CashPRRpt")?SessionID=@SessionID');
    });

    $(document).ready(function () {
        setTimeout(function () { $("#FromDate").focus(); }, 500);

        SetHeightGrid("grvtblVoucherList", 360);

        codeBasePopup.SetEntityDetail('SYS_tblVoucherList');

        var today = new Date();

        SetDate("FromDate", new Date(today.getYear()+1900, today.getMonth(), 1));
        SetDate("ToDate", new Date(today.getYear() + 1900, today.getMonth() + 1, 0));
        SetCombobox("AuditCode", "CR");
        SetCombobox("Status", "0");

    });


    function Print()
    {
        var grid = $("#grvtblVoucherList").data("kendoGrid");

        var datastring = 'SYS_tblVoucherList=' + JSON.stringify(grid.dataSource.data());

        PostServer('@Url.Action("UpdateData","CashPRRpt")', datastring);

        var para = "VoucherList= (SELECT * FROM SYS_tblVoucherList WHERE SessionID = '@SessionID' AND Selected = 1) T" // SQL&NoAttatches=" + $('#NoAttatches').val() + "&OrginalDocID=" + $('#OrginalDocID').val() + "&PayorName=" + $('#PayorName').val() + "&AlterAddress=" + $('#AlterAddress').val() + "&PrintAcct=" + $('#PrintAcct').is(':checked') + "&PrintName2=" + $('#PrintName2').is(':checked') + "&Lang=@LV.Controls.Web.Helper.LVCacheHelper.LoginUser.Language";; 


        if (GetCombobox("AuditCode") == "CR")
            codeBasePopup.Print("CS", "CS_tblCashReceipt", "rptCashReceipt", "Cash Receipt", "CS_sprReceiptVoucher", para);

        if (GetCombobox("AuditCode") == "CP")
            codeBasePopup.Print("CS", "CS_tblCashPayment", "rptCashPayment", "Cash Payment", "CS_sprPaymentVoucher", para);

    }

    function Cancel()
    {
        PostServer('@Url.Action("ClearSession","CashPRRpt")?SessionID=@SessionID');
        codeBasePopup.Close();
    }

    function Filter()
    {
        var FdatePicker = $("#FromDate").data("kendoDatePicker");
        var TdatePicker = $("#ToDate").data("kendoDatePicker");

        if (GetDate("FromDate") == "" || GetDate("FromDate") == null) {
            window.parent.ShowMessageErrorLevel1("FieldNotNull", "FieldNotNull", function (e) {
                var date = $("#FromDate").data("kendoDatePicker");
                date.focus();

            }, getLabel("lblFromDate"));
            return;
        }

        if (GetDate("ToDate") == "" || GetDate("ToDate") == null) {
            window.parent.ShowMessageErrorLevel1("FieldNotNull", "FieldNotNull", function (e) {
                var date = $("#ToDate").data("kendoDatePicker");
                date.focus();

            }, getLabel("lblToDate"));
            return;
        }

        PostServer('@Url.Action("LoadData","CashPRRpt")?SessionID=@SessionID&FromDate=' + kendo.toString(FdatePicker.value(), 'dd/MM/yyyy') + '&ToDate=' + kendo.toString(TdatePicker.value(), 'dd/MM/yyyy') + '&AuditCode=' + GetCombobox("AuditCode") + '&BatchNo=' + $('#BatchNo').val() + '&Status=' + GetCombobox("Status") + '&Selected=true');
        ReloadGridData("grvtblVoucherList");
    }

    function Select() {
        var FdatePicker = $("#FromDate").data("kendoDatePicker");
        var TdatePicker = $("#ToDate").data("kendoDatePicker");

        if (GetDate("FromDate") == "" || GetDate("FromDate") == null) {
            window.parent.ShowMessageErrorLevel1("FieldNotNull", "FieldNotNull", function (e) {
                var date = $("#FromDate").data("kendoDatePicker");
                date.focus();

            }, getLabel("lblFromDate"));
            return;
        }

        if (GetDate("ToDate") == "" || GetDate("ToDate") == null) {
            window.parent.ShowMessageErrorLevel1("FieldNotNull", "FieldNotNull", function (e) {
                var date = $("#ToDate").data("kendoDatePicker");
                date.focus();

            }, getLabel("lblToDate"));
            return;
        }

        PostServer('@Url.Action("LoadData","CashPRRpt")?SessionID=@SessionID&FromDate=' + kendo.toString(FdatePicker.value(), 'dd/MM/yyyy') + '&ToDate=' + kendo.toString(TdatePicker.value(), 'dd/MM/yyyy') + '&AuditCode=' + GetCombobox("AuditCode") + '&BatchNo=' + $('#BatchNo').val() + '&Status=' + GetCombobox("Status") + '&Selected=true');
        ReloadGridData("grvtblVoucherList");
    }

    function UnSelect() {
        var FdatePicker = $("#FromDate").data("kendoDatePicker");
        var TdatePicker = $("#ToDate").data("kendoDatePicker");

        if (GetDate("FromDate") == "" || GetDate("FromDate") == null) {
            window.parent.ShowMessageErrorLevel1("FieldNotNull", "FieldNotNull", function (e) {
                var date = $("#FromDate").data("kendoDatePicker");
                date.focus();

            }, getLabel("lblFromDate"));
            return;
        }

        if (GetDate("ToDate") == "" || GetDate("ToDate") == null) {
            window.parent.ShowMessageErrorLevel1("FieldNotNull", "FieldNotNull", function (e) {
                var date = $("#ToDate").data("kendoDatePicker");
                date.focus();

            }, getLabel("lblToDate"));
            return;
        }

        PostServer('@Url.Action("LoadData","CashPRRpt")?SessionID=@SessionID&FromDate=' + kendo.toString(FdatePicker.value(), 'dd/MM/yyyy') + '&ToDate=' + kendo.toString(TdatePicker.value(), 'dd/MM/yyyy') + '&AuditCode=' + GetCombobox("AuditCode") + '&BatchNo=' + $('#BatchNo').val() + '&Status=' + GetCombobox("Status") + '&Selected=false');
        ReloadGridData("grvtblVoucherList");
    }

</script>